package com.kehutong.payfees.admin;

import com.kehutong.common.util.Token;
import com.kehutong.payfees.service.ChargeInstrumentTypeServiceImpl;
import org.coraframework.authz.HasPermission;
import org.coraframework.bean.valid.ValidResult;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.Bean;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;
import org.coraframework.orm.jdbc.JdbcSession;

import com.kehutong.payfees.entity.ChargeInstrumentType;

@MvcAction
@ReqMapping("/admin/charge/instrument")
public class ChargeInstrumentTypeAction {

    @Inject
    private JdbcSession sqlSession;

    @Inject
    private ChargeInstrumentTypeServiceImpl chargeInstrumentTypeServiceImpl;

    @HasPermission("charge:instrument:view")
    @ReqMapping("/list")
    public Object list(JSONObject jsonObject) {
        return Result.success(chargeInstrumentTypeServiceImpl.list(jsonObject));
    }

    @HasPermission("charge:instrument:view")
    @ReqMapping("/listAll")
    public Object listAll(JSONObject jsonObject) {
        return Result.success(chargeInstrumentTypeServiceImpl.listAll(jsonObject));
    }

    @HasPermission("charge:instrument:view")
    @ReqMapping("/get")
    public Object get(ChargeInstrumentType item) {
        return Result.success(item);
    }


    @Bean(newInstance=true, copy=true)
    @HasPermission("charge:instrument:edit")
    @ReqMapping("/save")
    public Object save(Token token, ChargeInstrumentType item, ValidResult result) throws Exception {
        if (result.hasError()) {
            return Result.error(0, result.getErrorMessage());
        }
        return chargeInstrumentTypeServiceImpl.save(token, item);
    }

    @Bean(copy=true)
    @HasPermission("charge:instrument:edit")
    @ReqMapping("/update")
    public Object update(Token token, ChargeInstrumentType item, ValidResult result) throws Exception {
        if (result.hasError()) {
            return Result.error(0, result.getErrorMessage());
        }
        return chargeInstrumentTypeServiceImpl.update(token, item);
    }

    @HasPermission("charge:instrument:edit")
    @ReqMapping("/delete")
    public Object delete(ChargeInstrumentType item) {
        return chargeInstrumentTypeServiceImpl.delete(item.getId());
    }
}
